/**
 * 项目名称: LCR_140.cpp
 * 项目路径: study/DataStructure/LinkedList/LeetCode/剑指Offer
 * 编辑时间: 2024年06月28日19时52分51秒
 * 用   户: 轻尘
 */

#include <bits/stdc++.h>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;

    ListNode() : val(0), next(nullptr) {}

    ListNode(int x) : val(x), next(nullptr) {}

    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode *trainingPlan(ListNode *head, int cnt) {
        if (!head)return nullptr;

        ListNode *per = nullptr, *op = head, *tmp = nullptr;
        while (op) {
            tmp = op->next;
            op->next = per;
            per = op;
            op = tmp;
        }
        delete tmp;

        int cntS = 1;
        op = per;
        while (op) {
            if (cntS == cnt) {
                op->next = nullptr;
                break;
            }
            cntS++;
            op = op->next;
        }

        ListNode *perq = nullptr, *opq = per, *tmpq = nullptr;
        while (opq) {
            tmpq = opq->next;
            opq->next = perq;
            perq = opq;
            opq = tmpq;
        }
        delete tmpq,opq;
        return perq;
    }
};

int main() {

    return 0;
}
